<template>
  <el-dialog
    top="15%"
    width="420px"
    title="项目确认"
    append-to-body
    :visible.sync="visible"
    :before-close="beforeClose"
  >
    <div class="font-weight-normal p-2">是否确认通过：{{ formData.customer_name }} ？</div>
    <div class="text-right">
      <el-button type="primary" :loading="buttonLoading" @click="handleUpdata(1)">通过</el-button>
      <el-button type="danger" :loading="buttonLoading" @click="handleUpdata(2)">拒绝</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: Boolean,
    formData: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      tableName: 'datum_one_county_industry',
      buttonLoading: false,
    }
  },

  created() {},
  methods: {
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleUpdata(value) {
      this.buttonLoading = true
      this.$api
        .updateData(this.$serviceName, this.tableName, this.formData.customer_related_id, {
          is_pass: value,
        })
        .then(() => {
          if (+value === 1) {
            this.$message.success('项目已通过')
          } else {
            this.$message.error('项目已拒绝')
          }
          this.$store.dispatch('getTaskCountHnd')
          this.$emit('success', true)
          this.beforeClose()
        })
        .catch(err => {
          this.$message.error(err)
        })
        .finally(() => {
          this.buttonLoading = false
        })
    },
  },
}
</script>
<style lang="scss" scoped></style>
